package com.superjson.showpro.controller;

import com.superjson.showpro.service.EvaluateService;
import com.superjson.showpro.shared.enums.EvaluateResultEnum;
import com.superjson.showpro.shared.result.Result;
import com.superjson.showpro.shared.result.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

import static com.beantools.util.ObjectUtil.isNotNull;
import static com.beantools.util.ObjectUtil.isNull;
import static com.superjson.showpro.shared.result.ResultCodeEnum.EMPTY_CONTENT_TYPE;
import static com.superjson.showpro.shared.result.ResultCodeEnum.NO_ARTICLE;
import static com.superjson.showpro.shared.util.CommonUtil.ifNullThrow;
import static com.superjson.showpro.shared.util.CommonUtil.ifTrueThrow;

/**
 * Created By zby on 0:30 2019/5/29
 * 评价文章
 */
@RestController("evaluateController")
@RequestMapping("/evaluate")
public class EvaluateController {

    @Autowired
    private EvaluateService evaluateService;

    /**
     * Created By zby on 14:22 2019/6/14
     * 保存
     */
    @RequestMapping(value = "/save", method = RequestMethod.GET)
    public Result saveEvaluate(HttpServletRequest request, EvaluateResultEnum resultEnum, Long articleId) {
        ifNullThrow(resultEnum, EMPTY_CONTENT_TYPE);
        ifTrueThrow(isNull(articleId) || articleId <= 0, NO_ARTICLE);
        evaluateService.saveEvaluate(request, articleId, resultEnum);
        return ResultUtil.buildSuccess();
    }

}
